package org.example.struct.array;

import com.alibaba.fastjson.JSON;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * @author liyishan
 * @date 2023/8/1 10:09
 * @apiNote
 */

public class Test00217ContainsDuplicate {
    public static void main(String[] args) {
        int[] a = new int[]{1, -1, 1, -1, 1, -1,1};
        boolean count = test(a);
        System.out.println(count + "  array:" + JSON.toJSON(a));
    }


    public static boolean test(int[] nums) {
        Arrays.sort(nums);
        for(int i = 0;i <nums.length-1;i++){
            if(nums[i] == nums[i+1]){
                return true;
            }
        }
        return false;
    }

    public static boolean test1(int[] nums){
        Map<Integer,Integer> map = new HashMap<>();
        for(int i=0;i<nums.length;i++){
            if(!map.containsKey(nums[i])){
                map.put(nums[i],1);
            }else{
                return true;
            }
        }
        return false;
    }

}
